function linebreak(x)
%LINEBREAK Line break chart.
%   LINEBREAK(X) plots the asset data, X, in a line break chart.   X is an Mx2
%   matrix where the first column contains date numbers and the second
%   column is the asset price.    
%
%   See also BOLLING, CANDLE, HIGHLOW, MOVAVG, PRICEANDVOL, VOLAREA, KAGI, RENKO.

%	Copyright 1995-2007 The MathWorks, Inc.
%	$Revision: 1.1.6.2 $   $Date: 2007/11/22 16:40:00 $

%Get number of points
numpoints = size(x,1);

%Set tick bands
hi = max(x(1:2,2));
lo = min(x(1:2,2));

%Set first trend
if x(2,2) > x(1,2)
  
  %First line is up
  upd(1:3,1) = x(1,1);
  upd(1,2) = x(1,2);
  upd(2,2) = x(2,2);
  upd(3,2) = NaN;
  downd(1:3,1) = x(1,1);
  downd(1,2) = NaN;
  downd(2,2) = NaN;
  downd(3,2) = NaN;  
else
  
  %First line is down
  downd(1:3,1) = x(1,1);
  downd(1,2) = x(1,2);
  downd(2,2) = x(2,2);
  downd(3,2) = NaN;
  upd(1:3,1) = x(1,1);
  upd(1,2) = x(1,2);
  upd(2,2) = x(2,2);
  upd(3,2) = NaN;
end

%Initialize counters
k = 2;
j = 4;

%Build line data
for i = 3:numpoints
  
  if x(i,2) > hi
  
    %Up tick
    upd(j:j+2,1) = x(i,1);
    upd(j,2) = hi;
    upd(j+1,2) = x(i,2);

    %Set new hi level
    hi = x(i,2);
    lo = upd(j,2);
    upd(j+2,2) = NaN;
    
    %Fill in down tick placeholder for plotting
    downd(j:j+2,1) = x(i,1);
    downd(j,2) = NaN;
    downd(j+1,2) = NaN;
    downd(j+2,2) = NaN;  
    
    %Increment counters
    j = j + 3;
    k = k + 1;
    
  elseif x(i,2) < lo
    
    %Down tick
    downd(j:j+2,1) = x(i,1);
    downd(j,2) = lo;
    downd(j+1,2) = x(i,2);
    
    %Set new lo level
    lo = x(i,2);
    hi = downd(j,2);
    downd(j+2,2) = NaN;
    
    %Fill in up tick placeholder for plotting
    upd(j:j+2,1) = x(i,1);
    upd(j,2) = NaN;
    upd(j+1,2) = NaN;
    upd(j+2,2) = NaN;  
    
    %Increment counters
    j = j + 3;
    k = k + 1;
    
  end
  
end

%Display the up ticks
plot(upd(:,1),upd(:,2),'g','linewidth',4)
hold on

%Display the down ticks
plot(downd(:,1),downd(:,2),'r','linewidth',4)
hold off

%Turn on grid, set axis labels and x limits
grid on
datetick
set(gca,'Xlim',[downd(1,1)-1 downd(end,1)+1],'Tag','linebreakchart')

    
